<template>
	<view class="page ex-mall-tab-page" :class="[$themeClass('panel-content-bg-color')]">
		<view class="header-fill">
			<!-- #ifdef MP-WEIXIN -->
			<view class="ex-mall-header-mp-weixin-fill">发布</view>
			<!-- #endif -->
		</view>

		<view class="container">
			<view class="ex-mall-panel-title" :class="[$themeClass('panel-another-title-bg-color'), $themeClass('panel-another-title-color')]">
				<view class="title">即时链接商家与人脉</view>
			</view>
		<!-- 	<view class="header">
				<view class="title">即时链接商家与人脉</view>
			</view> -->
			<view class="ex-mall-panel classify">
				<view class="ex-mall-panel-content" :class="[$themeClass('panel-another-content-bg-color')]">
					<view class="list">
						<view class="item" :class="{'item-thumbnail': x.thumbnail}" :style="{'background-color':x.color}" v-for="(x, xi) in classifies" :key="xi">
							<view class="thumbnail" >
								<text class="text">{{x.name}}</text>
								<view class="emall_text">{{x.emall_name}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				classifies: [{
					name: '个人动态',
					emall_name:'社交内容会被同城推荐',
					color:'#FFE4E1'
				}, {
					name: '商品',
					emall_name:'推荐优质商品快速成交',
					color:'#E1FFFF'
				},{
					thumbnail: 'a',
					name: '红包信息',
					emall_name:'用红包宣传.圈粉.扩客.组团',
					color:'#A52A2A'
				}, {
					thumbnail: 'b',
					name: '城市红包雨',
					emall_name:'超低成本反复影响全城用户',
					color:'#ADD8E6'
				}]
			}
		},
		mounted() {
			this.load()
			this.$emit('loaded', {
				name: 'release'
			})
		},
		methods: {
			load() {
				console.log('relase on load')
			},
			checkedAll() {
				if (this.isCheckedAll) {
					this.isCheckedAll = false
					this.carts.forEach(x => this.$set(x, 'checked', false))
				} else {
					this.isCheckedAll = true
					this.carts.forEach(x => this.$set(x, 'checked', true))
				}
				this.calcTotal()
			},
			toggleChecked(cartItem) {
				var checked = !cartItem.checked
				this.$set(cartItem, 'checked', checked)
				if (checked) {
					if (this.carts.filter(x => x.checked).length === this.carts.length) {
						this.isCheckedAll = true
					}
				} else {
					this.isCheckedAll = false
				}
				this.calcTotal()
			},
			quantityPlus(cartItem) {
				if (!cartItem.stock || cartItem.quantity < cartItem.stock) {
					cartItem.quantity++
				}
				this.calcTotal()
			},
			quantityMinus(cartItem) {
				if (cartItem.quantity > 1) {
					cartItem.quantity--
				}
				this.calcTotal()
			},
			inputClick(cartItem) {
				this.$set(cartItem, 'inputting', true)
			},
			inputBlur(e) {
				var cartItem = this.carts[e.currentTarget.dataset.index]
				let value = e.detail.value
				cartItem.quantity = value
				if (!/(^\d+$)/.test(value) || value[0] == 0) value = 1
				if (value > cartItem.stock) {
					value = cartItem.stock
				} else if (value < 1) {
					value = 1
				}
				this.$nextTick(() => {
					cartItem.quantity = parseInt(value)
					cartItem.inputting = false
				})
				this.calcTotal()
			},
			calcTotal() {
				var totalAmount = 0
				this.carts.filter(x => x.checked).forEach(x => totalAmount += x.price * x.quantity)
				this.totalAmount = totalAmount
			}
		}
	}
</script>

<style lang="scss">
	.ex-mall-panel.classify {
		.ex-mall-panel-content {
			padding-bottom: 24px;
	
			&>.list {
				display: flex;
				flex-wrap: wrap;
				justify-content: space-between;
				padding: 0 28px;
	
				&>.item {
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					color: #333;
					width: 41vw;
					height: 58px;
					margin-top: 10px;
					background-color: #FFFFFF;
					border: 2px solid #9093A2;
					border-radius: 12px;
					overflow: hidden;
					box-sizing: border-box;
	
					&:nth-child(1),
					&:nth-child(2) {
						margin-top: 0;
					}
					&>.thumbnail {
						text-align: center;
						&>.text {
							font-size: 15px;
							font-weight: 600;
						}
						&>.emall_text {
							font-size: 10px;
							// color: #999999;
							font-weight: 300;
						}
					}
				}
	
				&>.item-thumbnail {
					position: relative;
					height: 41vw;
					border: none;
	
					&>.thumbnail {
						width: 100%;
						height: 100%;
						color: #FFFFFF;
						display: flex;
						flex-direction: column;
						justify-content: center;
						align-items: center;
						&>.emall_text {
							color: #FFFFFF;
						}
					}
	
					&:nth-child(4n-3) {
						&>.thumbnail {
							background-color: #98847D;
						}
					}
	
					&:nth-child(4n-2) {
						&>.thumbnail {
							background-color: #A06441;
						}
					}
				}
			}
		}
	}
	
	
	
	
	.page {
		&>.header-fill {
			padding: 0 28px;
			padding-top: calc(16px + var(--status-bar-height));
			background-color: #FFFFFF;
			
			&>.ex-mall-header-mp-weixin-fill {
				color: #3D3D3D;
			}
		}

		&>.container {
			/* #ifndef MP-WEIXIN */
			height: calc(100vh - 78px - 114px - 16px - var(--status-bar-height));
			/* #endif */
			/* #ifdef MP-WEIXIN */
			height: calc(100vh - 78px - 114px - 16px - var(--status-bar-height) - 50px);
			/* #endif */
			background-color: #FFFFFF;
			border-radius: 0 0 2em 2em;
			overflow-y: scroll;

			&>.header {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 12px 28px 28px 28px;
				background-color: #FFFFFF;

				&>.title {
					font-size: 18px;
					font-weight: 600;
				}

				&>.btns {
					display: flex;

					&>.btn {
						margin-left: 16px;
					}
				}
			}

			&>.content.list {
				padding-top: 10px;

				&>.item {
					display: flex;
					justify-content: space-between;
					padding: 0 28px 28px 28px;

					&:nth-child(4n-3) {
						&>.left {
							&>.thumbnail {
								&>.img {
									background-color: #0EAA90;
								}
							}
						}
					}

					&:nth-child(4n-2) {
						&>.left {
							&>.thumbnail {
								&>.img {
									background-color: #F8E3DC;
								}
							}
						}
					}

					&:nth-child(4n-1) {
						&>.left {
							&>.thumbnail {
								&>.img {
									background-color: #A8A8A9;
								}
							}
						}
					}

					&:nth-child(4n) {
						&>.left {
							&>.thumbnail {
								&>.img {
									background-color: #7F8688;
								}
							}
						}
					}

					&>.left {
						display: flex;
						align-items: center;
						flex: 1;

						&>.checkbox {
							&>.icon {
								font-size: 20px;
								color: #9093A2;
							}
						}

						&>.thumbnail {
							margin-left: 12px;

							&>.img {
								display: block;
								width: 88px;
								height: 88px;
								border-radius: 12px;
							}
						}

						&>.info {
							margin: 0 18px;
							line-height: 1;

							&>.title {
								line-height: 1.3;
								font-size: 15px;
								font-weight: 600;

								&>.spec {
									margin-left: 0.5em;
									color: #808080;
								}
							}

							&>.price {
								margin-top: 10px;
								font-size: 13px;
							}
						}
					}

					&>.right {
						height: 88px;
						background-color: #F7F7F7;
						border-radius: 12px;
						overflow: hidden;

						&>.numberbox {
							display: flex;
							flex-direction: column;

							&>.icon {
								display: flex;
								justify-content: center;
								align-items: center;
								width: 48px;
								height: 35px;
								font-size: 18px;
								font-weight: bold;

								&.plus {
									color: #61DAD5;
								}

								&.minus {
									color: #9093A2;
								}
							}

							&>.input {
								display: flex;
								justify-content: center;
								align-items: center;
								width: 48px;
								height: 18px;
								padding: 0 4px;
								text-align: center;
								font-size: 13px;
								color: #666666;
								box-sizing: border-box;
							}
						}
					}
				}
			}
		}

		&>.footer {
			padding: 28px;

			.btn {
				display: flex;
				justify-content: space-between;
				align-items: center;
				width: 100%;
				height: 58px;
				padding: 0 28px;
				border-radius: 12px;
				box-sizing: border-box;
			}

			&>.submit {
				&>.label {
					font-size: 15px;
					font-weight: 600;
				}

				&>.amount {
					font-size: 14px;
				}
			}

			&>.remove {
				&>.btn {
					justify-content: center;
				}
			}
		}
	}
</style>
